<?php
class StocksController extends AppController {
    public function index() {
        $this->layout = 'pharmarket';
        $this->Stock->recursive = 3;
        $stocks = $this->Stock->find('all');
        $this->set('stocks', $stocks);
    }

    public function edit($id){
        if ($this->request->is(array('post', 'put'))) {
            $this->Stock->id = $id;
            $this->Stock->set($this->data);
            if ($this->Stock->validates()) {
                if ($this->Stock->save($this->request->data)) {
                    return $this->redirect(array('action' => 'index'));
                }
            } else {
                $errors = $this->Stock->validationErrors;
                $this->set('errors', $errors);
            }
        }

        $conditions = array('conditions' => array('Stock.id = ' => $id));
        $this->Stock->recursive = 3;
        $stock = $this->Stock->find('all', $conditions);

        $this->set('stock', $stock);
        $this->layout = 'pharmarket';
    }
}